<?php 
/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
* @subpackage Menu
*/
class DomFgMenuLink {

	protected $title;
	
	protected $icon;
	
	protected $link;
	
	protected $items = array();
	
	protected $separator = false;
	
	public function __construct( $title = NULL, $link = NULL, $icon = NULL ) {
		$this->title = $title;
		$this->link = $link;
		$this->icon = $icon;
	}
	
	public function title( $title ) {
		$this->title = $title;
	}
	
	public function link( $link ) {
		$this->link = $link;
	}
	
	public function icon( $icon ) {
		$this->icon = $icon;
	}
	
	public function separator( $separator ) {
		$this->separator = $separator;
	}
	
	public function addItem( DomFgMenuLink $link  ) {
		return $this->items[] = $link;
	}
	
	public function addLink( DomFgMenuLink $link  ) {
		return $this->addItem( $link );
	}
	
	public function addSeparator() {
		$link = $this->items[count($this->items)-1];
		$link->separator(true);
		return $link;
	}
	
	public function parse() {
		$str = '["'.$this->title.'","'.$this->link.'","'.$this->icon.'", [';
		foreach( $this->items as $link )
			$str .= ','.$link->parse();
		$str .= ']],';
		
		if( $this->separator ) {
			$str.= '["separator","","",[]],';
		}
		return $str;
	}
	
	public function __get( $var ) {
		return $this->$var;
	}
	
	public static function getDefaultChild() {
		return 'menuLink';
	}
	
}
?>